package com.yx.cloud.activity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.view.View;
import android.widget.TextView;

import com.yx.cloud.R;
import com.yx.cloud.base.BaseActivity;
import com.yx.cloud.databinding.VideopolicyActivityBinding;
import com.yx.cloud.utils.Intent_utils;
import com.yx.cloud.utils.RomUtils;
import com.yx.cloud.utils.SharedPrefsUtil;

/**
 * 摄像头政策隐私
 */
public class VideoPolicyActivity extends BaseActivity implements View.OnClickListener {
    private VideopolicyActivityBinding binding;
    private String policy;
    private boolean valuePolicy;

    @Override
    protected void onCreate() {
        super.onCreate();
        binding = VideopolicyActivityBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initData();
    }

    private void initData() {

        policy = getIntent().getStringExtra("Policy");
        if ("home".equals(policy)) {
            //家居环境识别
            binding.tvPolicyTitle.setText(getString(R.string.MV_Video_Env_Privacy_title));
            binding.tvPolicyTitle2.setText(getString(R.string.MV_Video_Env_Privacy_title));
            binding.tvPolicyContent.setText(getString(R.string.MV_Video_Env_Privacy));
            valuePolicy = SharedPrefsUtil.getValue(this, "homePolicyState", "home_Polic", false);
        } else if ("video".equals(policy)) {
            //实时视频
            binding.tvPolicyTitle.setText(getString(R.string.MV_Video_Privacy_title));
            binding.tvPolicyTitle2.setText(getString(R.string.MV_Video_Privacy_title));
            binding.tvPolicyContent.setText(getString(R.string.MV_Video_LivePhoto_Privacy));
            valuePolicy = SharedPrefsUtil.getValue(this, "VodeoPolicyState", "Vodeo_Polic", false);
        }
        if (valuePolicy) {
            binding.btnVideoPolicyState.setText(getString(R.string.U_Unagree_Title));
            binding.btnVideoPolicyState.setTextColor(getResources().getColor(R.color.textview_color1));
            binding.btnVideoPolicyState.setBackgroundResource(R.drawable.checked_btn_background2);
        } else {
            binding.btnVideoPolicyState.setText(getString(R.string.L_Privacy_Btn_Agree));
            binding.btnVideoPolicyState.setTextColor(getResources().getColor(R.color.white));
            binding.btnVideoPolicyState.setBackgroundResource(R.drawable.checked_btn_background);
        }

        binding.ivVideoPolicyReturn.setOnClickListener(this);
        binding.btnVideoPolicyState.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        int id = v.getId();
        if (id == R.id.iv_videoPolicyReturn) {
            Intent_utils.backIntent(this);
        } else if (id == R.id.btn_videoPolicyState) {
            if (binding.btnVideoPolicyState.getText().toString().trim().equals(getString(R.string.U_Unagree_Title))) {
                revocationHintDialog(getString(R.string.U_Unagree_Title), getString(R.string.U_Unagree_Tip));
            } else if (binding.btnVideoPolicyState.getText().toString().trim().equals(getString(R.string.L_Privacy_Btn_Agree))) {
                binding.btnVideoPolicyState.setText(getString(R.string.U_Unagree_Title));
                binding.btnVideoPolicyState.setTextColor(getResources().getColor(R.color.textview_color1));
                binding.btnVideoPolicyState.setBackgroundResource(R.drawable.checked_btn_background2);
                if ("home".equals(policy)) {
                    //家居环境识别
                    SharedPrefsUtil.putValue(this, "homePolicyState", "home_Polic", true);
                } else if ("video".equals(policy)) {
                    //实时视频
                    SharedPrefsUtil.putValue(this, "VodeoPolicyState", "Vodeo_Polic", true);
                }
            }
        }
    }

    private void revocationHintDialog(String dialogTitle, String content) {
        Dialog dialog = new Dialog(VideoPolicyActivity.this);
        dialog.setContentView(R.layout.outlogin_dialog);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.setCanceledOnTouchOutside(false);
        TextView mBtnOutLoginConfirm = dialog.findViewById(R.id.btn_outLoginConfirm);
        TextView mBtnOutLoginCancel = dialog.findViewById(R.id.btn_outLoginCancel);
        TextView mTvDialogTitle = dialog.findViewById(R.id.tv_dialogTitle);
        TextView mTvContent = dialog.findViewById(R.id.tv_content);
        mTvDialogTitle.setText(dialogTitle);
        mTvContent.setText(content);

        mBtnOutLoginConfirm.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("ResourceAsColor")
            @Override
            public void onClick(View v) {

                binding.btnVideoPolicyState.setText(getString(R.string.L_Privacy_Btn_Agree));
                binding.btnVideoPolicyState.setTextColor(getResources().getColor(R.color.white));
                binding.btnVideoPolicyState.setBackgroundResource(R.drawable.checked_btn_background);

                if ("home".equals(policy)) {
                    //家居环境识别
                    SharedPrefsUtil.putValue(VideoPolicyActivity.this, "homePolicyState", "home_Polic", false);
                } else if ("video".equals(policy)) {
                    //实时视频
                    SharedPrefsUtil.putValue(VideoPolicyActivity.this, "VodeoPolicyState", "Vodeo_Polic", false);
                }
                dialog.dismiss();
            }
        });
        mBtnOutLoginCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

}
